import {
  Component,
  ElementRef,
  EventEmitter,
  OnInit,
  Output,
} from '@angular/core';
import { fromEvent } from 'rxjs';
import { filter } from 'rxjs/operators';

@Component({
  selector: 'app-filter-pocket',
  templateUrl: './filter-pocket.component.html',
  styleUrls: ['./filter-pocket.component.less'],
})
export class FilterPocketComponent implements OnInit {
  @Output() enterEvt = new EventEmitter<boolean>();

  constructor(private el: ElementRef) {}

  ngOnInit(): void {
    fromEvent(this.el.nativeElement, 'keyup')
      .pipe(
        filter((res: any) => (res.target as HTMLElement).tagName === 'INPUT')
      )
      .subscribe((res: KeyboardEvent) => {
        if (res.code === 'Enter' || res.code === 'NumpadEnter') {
          this.enterEvt.emit(true);
        }
      });
  }
}
